Skip to content

feat(isMobilePhone): add support for Croatia (hr-HR) locale#2672

Open
abhu85 wants to merge 1 commit intovalidatorjs:masterfrom
abhu85:feat/croatia-phone-hr-HR
Open

feat(isMobilePhone): add support for Croatia (hr-HR) locale#2672
abhu85 wants to merge 1 commit intovalidatorjs:masterfrom
abhu85:feat/croatia-phone-hr-HR

Conversation

@abhu85
Copy link
Copy Markdown

@abhu85 abhu85 commented Mar 2, 2026

Summary

Add mobile phone validation support for Croatia (hr-HR locale).

Addresses #1761 (Mobile Phone validations - For The First Time Contributors)

Changes

  • Add hr-HR regex pattern to isMobilePhone.js supporting:
    • Mobile prefixes: 91, 92, 95, 97, 98, 99
    • Format: +385 9X XXXXXXX or 09X XXXXXXX (10 digits local, 12 international)
  • Add comprehensive test cases (13 valid + 8 invalid numbers)
  • Update README.md to include hr-HR in locale list

Croatian Mobile Operators

Prefix Operator
91 T-Mobile (Hrvatski Telekom)
92, 95 A1 Hrvatska
97, 98, 99 Various (Tele2, etc.)

Test Plan

  • All 317 existing tests pass
  • 100% code coverage maintained
  • Linting passes
  • New locale tested with valid and invalid number formats

References

  • ITU-T E.164 numbering plan for Croatia
  • Croatian regulatory authority (HAKOM) numbering guidelines

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b1aea75) to head (363af92).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2672   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2595      2595           
  Branches       659       659           
=========================================
  Hits          2595      2595           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add mobile phone validation for Croatia with support for:
- Mobile prefixes: 91, 92, 95, 97, 98, 99
- Format: +385 9X XXXXXXX or 09X XXXXXXX (10 digits local, 12 international)

Croatian mobile operators:
- 91: T-Mobile (Hrvatski Telekom)
- 92, 95: A1 Hrvatska
- 97, 98, 99: Various operators (Tele2, etc.)

References:
- https://en.wikipedia.org/wiki/Telephone_numbers_in_Croatia
- ITU-T E.164 numbering plan

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@abhu85 abhu85 force-pushed the feat/croatia-phone-hr-HR branch from 35c1db9 to 363af92 Compare March 7, 2026 16:26
@rubiin rubiin requested a review from WikiRik March 7, 2026 16:32
@abhu85
Copy link
Copy Markdown
Author

abhu85 commented Mar 9, 2026

Hi maintainers 👋

Friendly ping on this PR adding Croatia (hr-HR) locale support for isMobilePhone. All tests passing and follows the existing locale patterns.

I also have a few other locale PRs open (#2670, #2671, #2667) if you'd like to batch review them together. Thanks!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Croatia (hr-HR) locale support to isMobilePhone by introducing a new validation regex, associated test vectors, and documenting the locale in the README locale list.

Changes:

  • Add hr-HR regex to src/lib/isMobilePhone.js.
  • Add hr-HR valid/invalid test cases in test/validators.test.js.
  • Update README isMobilePhone locale list to include hr-HR.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/lib/isMobilePhone.js Adds hr-HR locale regex to the phones map.
test/validators.test.js Adds a new hr-HR locale block with valid/invalid samples.
README.md Adds hr-HR to the documented isMobilePhone locale list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
'fr-WF': /^(\+681)?\d{6}$/,
'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
'hr-HR': /^(\+?385|0)(91|92|95|97|98|99)\d{7}$/,
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hr-HR regex only matches contiguous digits after the country code/prefix and will reject formats with spaces (e.g. +385 91 1234567 / 091 1234567). The PR description says those spaced formats should be supported, so either update the regex to allow the expected separators (consistent with other locales like cs-CZ, fi-FI, etc.) or adjust the stated supported format.

Copilot uses AI. Check for mistakes.
Comment on lines +8060 to +8073
'+385911234567',
'+385921234567',
'+385951234567',
'+385971234567',
'+385981234567',
'+385991234567',
'385911234567',
'0911234567',
'0921234567',
'0951234567',
'0971234567',
'0981234567',
'0991234567',
],
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added hr-HR test cases don’t include the space-separated formats called out in the PR description (e.g. +385 9X XXXXXXX / 09X XXXXXXX). If those formats are intended to be supported, add representative valid examples (and potentially a couple invalid spacing variants) so the behavior is covered and won’t regress.

Copilot uses AI. Check for mistakes.
**isMD5(str)** | check if the string is a MD5 hash.<br/><br/>Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA).
**isMimeType(str)** | check if the string matches to a valid [MIME type][MIME Type] format.
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-DJ', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'mk-MK', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`.
**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,<br/><br/>`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hr-HR', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'mk-MK', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).<br/><br/>`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`.
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isMobilePhone README locale list still contains incorrect locale casing (am-Am, ro-Md) on this line. These don’t match the actual locale keys (am-AM, ro-MD) exported by validator.isMobilePhoneLocales, which can mislead consumers copying from the docs. Please correct the locale codes while updating this line.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhu85 fix these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants